﻿using System;
using System.Text;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Pages_HomePage_DetailCompetion : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        lblWarning.Visible = false;
        if (!IsPostBack)
        {
            getimg();
            getCompetition();
        }
    }

    private void getimg()
    {
        CommonBUS com = new CommonBUS();
        collectionPager.PageSize = 4;
        collectionPager.DataSource = com.GetImg().DefaultView;
        collectionPager.BindToControl = dtListImg;
        dtListImg.DataSource = collectionPager.DataSourcePaged;
    }

    public static string Filter(string _txt)
    {
        try
        {
            StringBuilder strBuilder = new StringBuilder();
            strBuilder.Insert(0, _txt);
            if (strBuilder.Length > 50)
            {
                return strBuilder.ToString().Substring(0, 250) + "...";
            }
            else
            {
                return strBuilder.ToString();
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }

    private void getCompetition()
    {
        Competition c = new Competition();
        CommonBUS com = new CommonBUS();
        string id = Request.QueryString["CID"];
        c = com.getDetailCompetition(id);
        lblNameDetail.Text = c.Name;
        lblDate.Text = Convert.ToDateTime(c.StartDate).ToString("MM/dd/yyyy");        
        txtDescription.Text = Filter(c.Description);
        lblShowEndDate.Text = c.EndDate;
        lblShowPostdate.Text = c.PostDate;
        lblShowStartdate.Text = c.StartDate;
        lblShowFirst.Text = c.FirstPrize;
        lblShowSecond.Text = c.SecondPrize;
        lblShowThird.Text = c.ThirdPrize;
        lblShowName.Text = c.Name;
        txtShowDescription.Text = c.Description;
        imgCompe.ImageUrl = "~/Images/Competition/" + c.CompImage;
    }

    protected void btnParticipated_Click(object sender, EventArgs e)
    {
        if (Session["Id"] == null)
        {
            Response.Redirect("~/Pages/HomePage/Login.aspx");
        }
        else
        {
            Response.Redirect("~/Pages/StudentPages/StudentUpload.aspx?id=" + Request.QueryString["CID"]);
        }
    }
}